package main

import (
	"flag"
	"fmt"
	"os"
	"risc-vm/common"
	"risc-vm/vm"
	"strings"
)

var (
	rom      = flag.String("r", "", "rom file path.")
	bitCount = flag.Int("b", 32, "RISC-V ISA version")
)
var bitCountList = []uint8{32, 64}

func main() {
	flag.Parse()
	if len(strings.TrimSpace(*rom)) == 0 {
		fmt.Println("no input file!")
		return
	}
	var _, res = common.IndexOf(common.UnpackArray(bitCountList), uint8(*bitCount))
	if !res {
		fmt.Printf("无效的RISC-V ISA version：%d\n", *bitCount)
		return
	}
	_, err := os.Stat(*rom)
	if os.IsNotExist(err) {
		fmt.Printf("file %s not found!\n", *rom)
		return
	}
	vm.Run(*rom, uint8(*bitCount))
}
